﻿using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.ViewportConstraints;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuperMicroWave.Views
{
    /// <summary>
    /// CurveView.xaml 的交互逻辑
    /// </summary>
    public partial class CurveView : UserControl
    {
        public CurveView()
        {
            InitializeComponent();

            ViewportAxesRangeConstraint constraint = new ViewportAxesRangeConstraint();
            constraint.YRange = new DisplayRange(0, 300);
            chartPlot.Viewport.Constraints.Add(constraint);
        }
    }

    public class DisplayRange
    {
        public double Start { get; set; }
        public double End { get; set; }
        public DisplayRange(double start, double end)
        {
            Start = start;
            End = end;
        }
    }
    public class ViewportAxesRangeConstraint : ViewportConstraint
    {
        public DisplayRange? XRange = null;
        public DisplayRange? YRange = null;

        public override DataRect Apply(DataRect oldVisible, DataRect newVisible, Viewport2D viewport)
        {
            if (XRange != null)
            {
                newVisible.XMin = XRange.Start;
                newVisible.Width = XRange.End - XRange.Start;
            }
            if(YRange != null)
            {
                newVisible.YMin = YRange.Start;
                newVisible.Height = YRange.End - YRange.Start;
            }
            return newVisible;
        }
    }
}
